package chart;

import java.io.BufferedReader;

import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Collections;
import java.util.Iterator;

import java.util.TreeSet;

public class IO {
	 
	public  static void in(double score) throws IOException {
		
		try(BufferedWriter indata=new BufferedWriter(new FileWriter("sound/chart.txt")))
		{
			set.add(score);
			Iterator<Double > iter=set.iterator();           //迭代器
			while(iter.hasNext())
			{
				indata.write(Double.toString(iter.next()));          //把分数存进文本中并换行
				indata.write('\n');
			}
		}catch(Exception e)
		{
			
		}
		 
	}
	 public static TreeSet<Double> set = new TreeSet<Double>(Collections.reverseOrder());//创建treeset集合
	 public static TreeSet<Double> out() {
		 try (BufferedReader outdata=new BufferedReader(new FileReader("sound/chart.txt"));){
			    String line;
			    while((line=outdata.readLine())!=null) {
			 
			        double d = Double.parseDouble(line);//将文本中每一行的数据存入进set
			        set.add(d);
			    }
			   
			} catch (Exception e) {
			    e.printStackTrace();
			    System.out.println("error");
			}
		 
		 return set;
	 }
}